<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        /* 3、伪元素法 ，给父元素添加这个类       
 
        /* .clearfix:after {
            content: "";
            display: block;
            height: 0;
            clear: both;
            visibility: hidden;
        }

        .clearfix {
            IE6、7 专有，照顾兼容性
            *zoom: 1;
        } */


        /* 以上是单伪元素，下面介绍双伪类 */
        .clearfix:before,
        .clearfix:after {
            content: "";
            display: table;
        }

        .clearfix:after {
            clear: both;
        }

        .clearfix {
            /* IE6、7 专有，照顾兼容性 */

            *zoom: 1;
        }

        .box {
            width: 500px;
            /* 父元素不添加高度，因此要清除浮动 ,如果不清除，那么footer这个盒子就会来占用box的位置*/
            background-color: #f5aeae;
            border: 5px solid #4dd2f3;
        }

        .NO1 {
            float: left;
            width: 100px;
            height: 80px;
            background-color: #666666;
        }

        .NO2 {
            float: left;
            width: 100px;
            height: 80px;
            background-color: #271dad;
        }

        .footer {
            width: 400px;
            height: 300px;
            background-color: #8fd37e;
        }
    </style>
</head>

<body>
    <div class="box clearfix">
        <div class="NO1"></div>
        <div class="NO2"></div>
    </div>
    <div class="footer"></div>
</body>

</html>